package com.singfan.script.importdata;

import com.singfan.core.dao.database.IBarberHairstyleDao;
import com.singfan.core.dao.database.model.BarberHairstyle;
import com.singfan.core.dao.database.model.constant.BusinessStatusType;
import com.singfan.core.dao.mongo.IHairstyleLocationDao;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.Date;

/**
 * Author: hansonghe
 * Date: 2015-08-20 12:14
 * Desc:
 */
@Component
public class HairstyleSheetParser extends SheetParser {
    @Autowired
    private IBarberHairstyleDao barberHairstyleDao;
    @Autowired
    private IHairstyleLocationDao hairstyleLocationDao;

    @Override
    protected void insertData(XSSFRow row) {
        Date now = new Date();

        int colIndex = 0;
        BarberHairstyle barberHairstyle = new BarberHairstyle();
        barberHairstyle.setId((long) row.getCell(colIndex++).getNumericCellValue());
        barberHairstyle.setHairstyleName(row.getCell(colIndex++).getStringCellValue());
        barberHairstyle.setBarberId((int) row.getCell(colIndex++).getNumericCellValue());
        barberHairstyle.setBarberName(row.getCell(colIndex++).getStringCellValue());
        barberHairstyle.setCityId((int) row.getCell(colIndex++).getNumericCellValue());
        barberHairstyle.setBusinessCircleId((int) row.getCell(colIndex++).getNumericCellValue());
        barberHairstyle.setLongitude(new BigDecimal(row.getCell(colIndex++).getNumericCellValue()));
        barberHairstyle.setLatitude(new BigDecimal(row.getCell(colIndex++).getNumericCellValue()));
        barberHairstyle.setPreferredImg(row.getCell(colIndex++).getStringCellValue());
        barberHairstyle.setImgList(row.getCell(colIndex++).getStringCellValue());
        barberHairstyle.setPrice((int) row.getCell(colIndex++).getNumericCellValue() * 100);
        barberHairstyle.setGender((int) row.getCell(colIndex++).getNumericCellValue());
        barberHairstyle.setOrderCount((int) row.getCell(colIndex++).getNumericCellValue());
        barberHairstyle.setHairstyleDesc(row.getCell(colIndex++).getStringCellValue());

        barberHairstyle.setStatus(BusinessStatusType.VERIFY_PASSED);
        barberHairstyle.setCreateTime(now);

        barberHairstyleDao.create(barberHairstyle);

        hairstyleLocationDao.createHairstyleLocation(barberHairstyle.getId(), barberHairstyle.getCityId(), barberHairstyle.getBusinessCircleId(), barberHairstyle.getGender(), barberHairstyle.getLongitude().doubleValue(), barberHairstyle.getLatitude().doubleValue());
    }
}
